# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.spark_submit import SparkSubmitOperator
from jms_hi.dwd.tab.dwd_tab_barscan_arrival_base_hi import jms_dwd__dwd_tab_barscan_arrival_base_hi
from jms_hi.dwd.tab.dwd_tab_barscan_send_base_hi import jms_dwd__dwd_tab_barscan_send_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_stop_union_base_hi import jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi
from jms_hi.dwd.tms.dwd_yl_tmsnew_branch_shipment_stop_base_hi import jms_dwd__dwd_yl_tmsnew_branch_shipment_stop_base_hi
from jms_hi.dwd.tms.dwd_tmsnew_shipment_union_base_hi import jms_dwd__dwd_tmsnew_shipment_union_base_hi
from jms_hi.dwd.other.dwd_electronic_package_list_base_hi import jms_dwd__dwd_electronic_package_list_base_hi
from jms_hi.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage


jms_dm__dm_tab_center_ship_summary_dt = SparkSubmitOperator(
    task_id='jms_dm__dm_tab_center_ship_summary_dt',
    conn_id='spark_route',
    email=['jokic.wang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tab_center_ship_summary_dt_{{ execution_date | cst_ds }}',
    # sla=timedelta(hours=7),
    driver_memory='4G',
    driver_cores=1,
    executor_memory='6G',
    executor_cores=5,
    num_executors=42,
    pool_slots=2,
    conf={'spark.dynamicAllocation.enabled': 'false',  # 动态资源开启
          'spark.shuffle.service.enabled': 'false',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 42,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 680,
          'spark.locality.wait.node': '100ms',
          'spark.yarn.maxAppAttempts': 1,
          'spark.shuffle.memoryFraction': '0.8',
          'spark.shuffle.file.buffer': '64K',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=5'
          },
    jars='hdfs:///scheduler/jms/spark/zql/prescription_new/common-1.0-SNAPSHOT.jar',
    # 依赖 jar 包
    java_class='com.yunlu.bigdata.jobs.tab.ShipExport',  # spark 主类
    application='hdfs:///scheduler/jms/spark/wsy/dm/tab/ship/original-jobs-1.0-SNAPSHOT.jar',
    # spark jar 包
    application_args=['{{ execution_date | cst_hour }}'],
    execution_timeout=timedelta(minutes=55),
)

jms_dm__dm_tab_center_ship_summary_dt << [
    jms_dwd__dwd_tab_barscan_arrival_base_hi,
    jms_dwd__dwd_tab_barscan_send_base_hi,
    jms_dwd__dwd_tmsnew_shipment_stop_union_base_hi,
    jms_dwd__dwd_yl_tmsnew_branch_shipment_stop_base_hi,
    jms_dwd__dwd_tmsnew_shipment_union_base_hi,
    jms_dwd__dwd_electronic_package_list_base_hi,
    jms_dim__dim_network_whole_massage
]
